package com.sunjie.server.impl;

import java.io.File;
import java.util.Date;

import com.sunjie.server.GeneratorPoServer;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.sunjie.bean.TableBean;
import com.sunjie.bean.TemplateBean;
import com.sunjie.utils.FreeMarkerTemplateUtils;

/**
 * @author sj
 * @date 2018/1/30
 */
@Service
public class GeneratorPoServerImpl implements GeneratorPoServer {

    @Value("${author}")
    private String author;
    @Value("${file.path}")
    private String filePath;

    @Value("${po.template.file}")
    private String templateFile;
    @Value("${po.package}")
    private String packageName;
    @Value("${po.suffix}")
    private String suffix;
    @Value("${po.serializable}")
    private Boolean serializables;

    @Override
    public void generateFile(TableBean tableBean) throws Exception {
        File mapperFile = new File("D://Po.java");
        String time = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
        TemplateBean templateBean = new TemplateBean(packageName, author, time, suffix, serializables, tableBean);
        FreeMarkerTemplateUtils.generateFileByTemplate(templateFile, mapperFile, templateBean);
    }
}
